package com.plumelog.lite.service;

import com.alibaba.fastjson.JSONObject;
import com.plumelog.core.client.AbstractServerClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Auther: duanhong
 * @Date: 2022/6/4 15:55
 */
@Service
public class ClientServiceImpl {
    @Autowired
    private AbstractServerClient abstractServerClient;

    public JSONObject get(String indexStr, String queryStr) throws Exception {
        String res = abstractServerClient.get(indexStr, queryStr);

        return getJsonObject(res);
    }


    public JSONObject get(String indexStr, String queryStr, String from, String size) throws Exception {
        String res = abstractServerClient.get(indexStr, queryStr, from, size);

        return getJsonObject(res);
    }

    public JSONObject cat(String index)  {
        String res = abstractServerClient.cat(index);

        return getJsonObject(res);
    }

    private JSONObject getJsonObject(final String res) {
        if (res == null) {
            return null;
        }
        return JSONObject.parseObject(res);
    }

}
